﻿using ATM.BUS;
using ATM.DAO;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATMSystem
{
    public partial class frmWithdraw : Form
    {
        private frmAskForReceipt frm1;
        private frmWithdrawOther frm2;
        private Account passedAcc;
        private Card passedCard;

        public frmWithdraw()
        {
            InitializeComponent();
        }

        public frmWithdraw(Account acc, Card card)
        {
            InitializeComponent();
            passedAcc = acc;
            passedCard = card;
        }

        void btnCancel1_Click(object sender, EventArgs e)
        {
            frm2.Close();
            this.Visible = true;
        }

        private void btnMoney_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            switch (btn.Tag.ToString())
            {
                case "Other":
                    frm2 = new frmWithdrawOther(passedAcc, passedCard);
                    //this.Visible = false;
                    frm2.Show();
                    frm2.btnCancel.Click += btnCancel1_Click;
                    break;
                default:
                    switch (WithdrawBUS.Withdraw(float.Parse(btn.Tag.ToString()), passedAcc, passedCard, 1))
                    {
                        case 0:
                            MessageBox.Show("The inserted amount is not valid!");
                            break;
                        case 1:
                            MessageBox.Show("Amount is out of your withdraw limit!");
                            break;
                        case 4:
                            MessageBox.Show("Can't withdraw!");
                            break;
                        default:
                            frm1 = new frmAskForReceipt();
                            frm1.Show();
                            break;
                    }
                    break;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
